<?php

namespace core\controller;

use core\traits\Response as TraitsResponse;
use core\traits\UcView as TraitsUcView;
use app\bll\UcenterIndexLayout as BllUcenterIndexLayout;
use app\bll\User as BllUser;
use app\bll\UserGrade as BllUserGrade;
use app\bll\UserMessage as BllUserMessage;
use support\View;

class UcBase
{
    use TraitsResponse;
    use TraitsUcView;

    public function __construct()
    {
        $this->assignLayout();
        $this->assignUserInfomation();
        $this->assignUnreadMessage();
    }

    /**
     * 渲染布局
     *
     * @return void
     */
    private function assignLayout()
    {
        $bllUcenterIndexLayout = new  BllUcenterIndexLayout();
        $layouts               = $bllUcenterIndexLayout->getLayout();
        View::assign('layouts', $layouts);
    }

    /**
     * 渲染用户信息
     *
     * @return void
     */
    private function assignUserInfomation()
    {
        //会员等级
        $bllUserGrade = new BllUserGrade();
        $nowGrade = $bllUserGrade->nowGradeRange(request()->userinfo['integral']);
        View::assign('nowGrade', $nowGrade);

        //用户基础信息
        $bllUser = new BllUser();
        $userBasicInfo = $bllUser->userInfomation('frame_user_basicinfo', request()->userinfo['id']);
        View::assign('userBasicInfo', $userBasicInfo);
    }

    /**
     * 未阅读站内信数量
     *
     * @return void
     */
    private function assignUnreadMessage()
    {
        $bllUserMessage = new BllUserMessage();
        $unreadCount = $bllUserMessage->unreadCount(request()->userinfo['id']);
        View::assign('messageUnreadCount', $unreadCount);
    }
}
